import authCheckApp from './authCheckApp'

/**
 * 打开群聊
 * @since 1.0.0
 * @param {Object} obj - 加入群的id
 * @param {string} obj.tribeId 群聊id
 * @returns {string} 返回打开群聊的状态
 * @example
 * 
 * openTribe({
 *   tribeId: '2250003386',
 * })
 */
function openTribe(obj) {
    return new Promise((reslove, reject) => {
        authCheckApp()
            .then(success => {
                // 发起请求
                window.WebViewJavascriptBridge.callHandler('openTribe', {
                    'tribeId': obj.tribeId
                }, (response) => {
                    if (typeof response === 'string') {
                        response = JSON.parse(response)
                    }
                    // 返回状态值为0成功
                    if (response.status === 0) {
                        resolve(response)
                    } else {
                        reject(response)
                    }
                })
            }).catch(err => {
                reject(err)
            })
    })
}

export default openTribe